/////////////////////////////////////////////////////////////////////////////
// Name:        ax_mediactrlpanel.h
// Purpose:     
// Author:      Julian Smart
// Modified by: 
// Created:     31/12/2008 18:16:16
// RCS-ID:      
// Copyright:   (c) Anthemion Software Limited
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#ifndef _AX_MEDIACTRLPANEL_H_
#define _AX_MEDIACTRLPANEL_H_


/*
 * Includes
 */

////@begin includes
#include "wx/mediactrl.h"
////@end includes

#include "wx/timer.h"

#include "ax_resource/ax_resource.h"
#include "ax/ax_ui_adaptation.h"

/*!
 * Forward declarations
 */

////@begin forward declarations
class wxMediaCtrl;
////@end forward declarations

class wxMediaEvent;

/*
 * Control identifiers
 */

////@begin control identifiers
#define SYMBOL_AXMEDIACTRLPANEL_STYLE wxRESIZE_BORDER|wxTAB_TRAVERSAL
#define SYMBOL_AXMEDIACTRLPANEL_TITLE wxEmptyString
#define SYMBOL_AXMEDIACTRLPANEL_IDNAME wxID_ANY
#define SYMBOL_AXMEDIACTRLPANEL_SIZE wxSize(20, 20)
#define SYMBOL_AXMEDIACTRLPANEL_POSITION wxDefaultPosition
////@end control identifiers


/**
    @class AxMediaCtrlPanel

    A player window for audio and video files.

    @category{ax_resource}

 */

class AxMediaCtrlPanel: public wxScrolledWindow
{    
    DECLARE_DYNAMIC_CLASS( AxMediaCtrlPanel )
    DECLARE_EVENT_TABLE()

public:
    /// Constructors
    AxMediaCtrlPanel();
    AxMediaCtrlPanel( wxWindow* parent, wxWindowID id = SYMBOL_AXMEDIACTRLPANEL_IDNAME, const wxPoint& pos = SYMBOL_AXMEDIACTRLPANEL_POSITION, const wxSize& size = SYMBOL_AXMEDIACTRLPANEL_SIZE, long style = SYMBOL_AXMEDIACTRLPANEL_STYLE );

    /// Creation
    bool Create( wxWindow* parent, wxWindowID id = SYMBOL_AXMEDIACTRLPANEL_IDNAME, const wxPoint& pos = SYMBOL_AXMEDIACTRLPANEL_POSITION, const wxSize& size = SYMBOL_AXMEDIACTRLPANEL_SIZE, long style = SYMBOL_AXMEDIACTRLPANEL_STYLE );

    /// Destructor
    ~AxMediaCtrlPanel();

    /// Initialises member variables
    void Init();

    /// Creates the controls and sizers
    void CreateControls();
    
    /// Set current playlist
    void SetPlaylist(const wxArrayString& playlist, bool clearFirst = true);
    void SetPlaylist(const AxResource& playlist, bool clearFirst = true);

    /// Get playlist
    //const shBookPartArray& GetPlaylist() const { return m_playlist; }

    /// Get current track
    int GetCurrentItem() const { return m_currentItem; }
    
    /// Play. Choose first if idx is -1.
    bool Play(int idx = -1);

    /// Is the control playing?
    bool IsPlaying() const;

    /// Is the control paused?
    bool IsPaused() const;

    /// Pause
    bool Pause();

    /// Resume
    bool Resume();

    /// Stop
    bool Stop();

    /// Clear playlist
    void ClearPlaylist();

    /// Go to start of the current item
    bool GoToStart();

    /// Go to end of the current item
    bool GoToEnd();

    /// Go to next item
    bool GoToNext();

    /// Go to previous item
    bool GoToPrevious();

    /// Finished
    void OnMediaFinished(wxMediaEvent& event);

    /// Media event handlers
    void OnMediaLoaded(wxMediaEvent& event);

    /// Returns true if the user is dragging the slider
    bool IsBeingDragged();

    /// Timer notification
    void Notify(wxTimerEvent& event);

    void OnBeginSeek(wxScrollEvent& event);
    void OnEndSeek(wxScrollEvent& event);

    /// Find index of parts by filename
    int FindByFilename(const wxString& filename) const;

    void SetAutoPlay(bool autoPlay) { m_autoPlay = autoPlay; }
    bool GetAutoPlay() const { return m_autoPlay; }

////@begin AxMediaCtrlPanel event handler declarations

    /// wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_MEDIACTRLPANEL_PLAYLIST
    void OnMediactrlpanelPlaylistSelected( wxCommandEvent& event );

    /// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_MEDIACTRLPANEL_PREVIOUS
    void OnMediactrlpanelPreviousClick( wxCommandEvent& event );

    /// wxEVT_UPDATE_UI event handler for ID_MEDIACTRLPANEL_PREVIOUS
    void OnMediactrlpanelPreviousUpdate( wxUpdateUIEvent& event );

    /// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_MEDIACTRLPANEL_PLAY
    void OnMediactrlpanelPlayClick( wxCommandEvent& event );

    /// wxEVT_UPDATE_UI event handler for ID_MEDIACTRLPANEL_PLAY
    void OnMediactrlpanelPlayUpdate( wxUpdateUIEvent& event );

    /// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_MEDIACTRLPANEL_STOP
    void OnMediactrlpanelStopClick( wxCommandEvent& event );

    /// wxEVT_UPDATE_UI event handler for ID_MEDIACTRLPANEL_STOP
    void OnMediactrlpanelStopUpdate( wxUpdateUIEvent& event );

    /// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_MEDIACTRLPANEL_NEXT
    void OnMediactrlpanelNextClick( wxCommandEvent& event );

    /// wxEVT_UPDATE_UI event handler for ID_MEDIACTRLPANEL_NEXT
    void OnMediactrlpanelNextUpdate( wxUpdateUIEvent& event );

    /// wxEVT_COMMAND_SLIDER_UPDATED event handler for ID_MEDIACTRLPANEL_VOLUME_SLIDER
    void OnMediactrlpanelVolumeSliderUpdated( wxCommandEvent& event );

////@end AxMediaCtrlPanel event handler declarations

////@begin AxMediaCtrlPanel member function declarations

    /// Retrieves bitmap resources
    wxBitmap GetBitmapResource( const wxString& name );

    /// Retrieves icon resources
    wxIcon GetIconResource( const wxString& name );
////@end AxMediaCtrlPanel member function declarations

    /// Should we show tooltips?
    static bool ShowToolTips();

////?@begin AxMediaCtrlPanel member variables
    wxMediaCtrl* m_mediaCtrl;
    wxListBox* m_playlistCtrl;
    wxSlider* m_timerSliderCtrl;
    wxButton* m_previousCtrl;
    wxButton* m_playCtrl;
    wxButton* m_stopCtrl;
    wxButton* m_nextCtrl;
    wxSlider* m_volumeSliderCtrl;
    /// Control identifiers
    enum {
        ID_MEDIACTRLPANEL_MEDIACTRL = 17401,
        ID_MEDIACTRLPANEL_PLAYLIST = 17402,
        ID_MEDIACTRLPANEL_TIME_SLIDER = 17407,
        ID_MEDIACTRLPANEL_PREVIOUS = 17403,
        ID_MEDIACTRLPANEL_PLAY = 17404,
        ID_MEDIACTRLPANEL_STOP = 17405,
        ID_MEDIACTRLPANEL_NEXT = 17406,
        ID_MEDIACTRLPANEL_VOLUME_SLIDER = 17408
    };
////?@end AxMediaCtrlPanel member variables

    AxResource      m_playlist;
    int             m_currentItem;
    bool            m_bIsBeingDragged;
    wxTimer         m_timer;
    bool            m_disableUpdates;
    bool            m_autoPlay;
    AxSelfVoicing   m_selfVoicing;
};

#endif
    // _AX_MEDIACTRLPANEL_H_
